var commonMethodTest = require('../../utils/commonMethods.js');
var expect = require('chai').expect;

describe('one replacement in URL', function() {
  it('should replace @shipmentNumber@ with 123456', function() {
    var data = "/wls_dom_shp/rest/shipment/lw/checkPointDoc/xml/@shipmentNumber@";
    var bizKeys = [{"bizKeyType" : "shipmentNumber","bizKeyValue":"123456"}];
    expect(commonMethodTest.replaceSourceDataWithKeyValue(data,bizKeys)).to.be.equal("/wls_dom_shp/rest/shipment/lw/checkPointDoc/xml/123456");
  });
});


describe('two replacement in URL', function() {
  it('should replace @shipmentNumber@ with 123456 and @CMSReference@ with cms123' , function() {
    var data = "/wls_dom_shp/rest/shipment/lw/checkPointDoc/xml/@shipmentNumber@/@CMSReference@";
    var bizKeys = [{"bizKeyType" : "shipmentNumber","bizKeyValue":"123456"},{"bizKeyType" : "CMSReference","bizKeyValue":"cms123"}];
    expect(commonMethodTest.replaceSourceDataWithKeyValue(data,bizKeys)).to.be.equal("/wls_dom_shp/rest/shipment/lw/checkPointDoc/xml/123456/cms123");
  });
});

describe('one replacement in strings', function() {
  it('should replace @shipmentNumber@ with 123456 and @CMSReference@ with cms123' , function() {
    var data = "\<checkPointRequiredDocumentList><checkPoint>MTY</checkPoint><isDocReceived>false</isDocReceived>"
        +"\<isDocRequired>false</isDocRequired></checkPointRequiredDocumentList><checkPointRequiredDocumentList>"
        + "\<checkPoint>RCV</checkPoint><isDocReceived>false</isDocReceived><isDocRequired>false</isDocRequired>"
        +"\</checkPointRequiredDocumentList><checkPointRequiredDocumentList><checkPoint>LOAD</checkPoint>"
        +"\<isDocReceived>false</isDocReceived><isDocRequired>true</isDocRequired><loadCallNumber>1</loadCallNumber>"
        +"\<loadFacility><code>HKG01</code><id>547558937096255</id><name>Modern Terminal Limited (MTL)</name>"
        +"\<timeZone>Asia/Hong_Kong</timeZone></loadFacility><loadVoyageCode>KTX3-OJK-092 S</loadVoyageCode>"
        "\</checkPointRequiredDocumentList><shipmentNumber>@shipmentNumber@</shipmentNumber></lightWeightCheckPointRequiredLegalDoc>";
    var result = "\<checkPointRequiredDocumentList><checkPoint>MTY</checkPoint><isDocReceived>false</isDocReceived>"
        +"\<isDocRequired>false</isDocRequired></checkPointRequiredDocumentList><checkPointRequiredDocumentList>"
        + "\<checkPoint>RCV</checkPoint><isDocReceived>false</isDocReceived><isDocRequired>false</isDocRequired>"
        +"\</checkPointRequiredDocumentList><checkPointRequiredDocumentList><checkPoint>LOAD</checkPoint>"
        +"\<isDocReceived>false</isDocReceived><isDocRequired>true</isDocRequired><loadCallNumber>1</loadCallNumber>"
        +"\<loadFacility><code>HKG01</code><id>547558937096255</id><name>Modern Terminal Limited (MTL)</name>"
        +"\<timeZone>Asia/Hong_Kong</timeZone></loadFacility><loadVoyageCode>KTX3-OJK-092 S</loadVoyageCode>"
    "\</checkPointRequiredDocumentList><shipmentNumber>123456</shipmentNumber></lightWeightCheckPointRequiredLegalDoc>";
    var bizKeys = [{"bizKeyType" : "shipmentNumber","bizKeyValue":"123456"}];
    expect(commonMethodTest.replaceSourceDataWithKeyValue(data,bizKeys)).to.be.equal(result);
  });
});